package com.example.batch.monitor.autoconfigure;

import com.example.batch.monitor.core.DataSourceMonitor;
import com.example.batch.monitor.core.DetailedMetricsCollector;
import io.micrometer.core.instrument.MeterRegistry;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 监控自动配置类
 */
@Configuration
@ConditionalOnClass(MeterRegistry.class)
@EnableConfigurationProperties(MonitorProperties.class)
@ConditionalOnProperty(prefix = "spring.batch.monitor", name = "enabled", havingValue = "true")
public class MonitorAutoConfiguration {

    /**
     * 配置详细指标收集器
     */
    @Bean
    @ConditionalOnMissingBean
    public DetailedMetricsCollector detailedMetricsCollector(
            MeterRegistry registry,
            MonitorProperties properties) {
        return new DetailedMetricsCollector(
            registry,
            properties.getApplicationName(),
            properties);
    }
    
    /**
     * 配置数据源监控
     */
    @Bean
    @ConditionalOnMissingBean
    public DataSourceMonitor dataSourceMonitor(
            MeterRegistry registry,
            MonitorProperties properties) {
        return new DataSourceMonitor(registry, properties);
    }
    
    // ... 其他Bean配置
} 